package borge.web.teamspirit.client.page.team.widgets;

import java.util.List;

import borge.web.teamspirit.client.TeamSpirit;
import borge.web.teamspirit.client.TeamSpiritConstants;
import borge.web.teamspirit.client.data.Person;
import borge.web.teamspirit.client.data.TeamPlayer;
import borge.web.teamspirit.client.interfaces.WidgetEventHandler;
import borge.web.teamspirit.client.interfaces.WidgetEventHandler.WidgetEventType;

/**
 * Display a list of players in the team
 * @author 23052438
 *
 */
@SuppressWarnings("unchecked")
public class ListPersonsWidget extends ListDataWidget<Person> {
	
    //private List<Player> iPlayers;
    
    public ListPersonsWidget(WidgetEventHandler aEventHandler, List<Person> aPersons){
        super(aEventHandler, WidgetEventType.EDIT_PERSON, 
                WidgetEventType.DELETE_PERSON,
                WidgetEventType.SHOW_PERSON);
        iData = aPersons;
        
        
        createDataTable();
        
        initWidget(iPanel);
    }
    
    protected void createDataTable(){
    	
    	reset();
    	
		TeamSpiritConstants lcs = TeamSpirit.getConstants();
		int row = 0;
		int col = 0;

		// We should only show first name, second name, edit and delete later
		//iTable.setText(row, col++, lcs.id());
		iTable.setText(row, col++, lcs.first_name());
		iTable.setText(row, col++, lcs.last_name());
		iTable.setText(row, col++, lcs.username());
		//iTable.setText(row, col++, lcs.position());
		//iTable.setText(row, col++, lcs.edit());
		//iTable.setText(row, col++, lcs.delete());
		row++;

		for (Person p : iData) {
			col = 0;

			//iTable.setText(row, col++, p.getPlayerId().toString());
			iTable.setText(row, col++, p.getFirstName());
			iTable.setText(row, col++, p.getLastName());
			iTable.setText(row, col++, p.getUserName());
			//iTable.setText(row, col++, p.getPosition());
			addButtons(row, col);

			row++;
		}

		iPanel.add(iTable);
		
    	
    }
    
    

}
